package com.yoyo.yyadsdk.serv;

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.yoyo.ad.main.IAdBannerListener;
import com.yoyo.ad.main.YoYoAdManager;
import com.yoyo.yyadsdk.R;
import com.yoyo.yyadsdk.config.PullFeature;

import static com.yoyo.yyadsdk.config.Constants.BANNER_DOWN;


public class WindowBDService extends WindowBaseService {

    private ViewGroup mContainer;

    @Override
    protected int getLayoutId() {
        return R.layout.common_banner;
    }

    @Override
    protected void initStyle(WindowManager.LayoutParams mParams) {
        mParams.gravity = Gravity.BOTTOM;
        mParams.width = WindowManager.LayoutParams.MATCH_PARENT;//窗口的宽和高
        mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        mParams.y = (int) (mHeight * 0.2);
    }

    @Override
    protected int getAdvType() {
        return PullFeature.ADV_BANNER_DOWN;
    }

    @Override
    protected void initInflate(View inflate) {
        mContainer = inflate.findViewById(R.id.container);
        inflate.findViewById(R.id.close_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                stopSelf();
            }
        });
    }

    @Override
    protected void initData() {
        mAdFactory = YoYoAdManager.getAdFactory(this, new IAdBannerListener() {
            @Override
            public void adShow(int requestCode) {
                loadSuccess();
            }

            @Override
            public void adClick(int requestCode) {
                stopSelf();
            }

            @Override
            public void adDismissed(int requestCode) {
                stopSelf();
            }

            @Override
            public void adFail(int requestCode, String arg0) {
                loadFail();
                stopSelf();
            }
        });
    }

    @Override
    public void onAdSuccess() {
        mAdFactory.getBanner(BANNER_DOWN, 1, mContainer, mWidth, mWidth * 3 / 20);
    }
}